<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script crossorigin="anonymous" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ"
            src="https://lib.baomitu.com/jquery/1.12.4/jquery.min.js"></script>

</head>
<body>

<div>用户名：<input type="text" id="name"></div>
<div>密码:<input type="password" id="password"></div>
<div><input type="button" value="登录" id="btnLogin"></div>


<script type="text/javascript">
    $(document).ready(function () {
        $("#btnLogin").click(function () {
            var name = $("#name").val();
            var password = $("#password").val();
            if (!name || !password) {
                alert('请检查表单必填项,用户名、密码全部都要填写')
                return;
            }

            $.get('/user/signIn', {
                name: name,
                password: password
            }, function (res) {
                if (res.code === 1) {
                    alert('登录成功');
                    console.log("用户令牌：" + res.data);
                    document.cookie = "token=" + res.data;
                    location.href = "/view/users";
                } else {
                    alert(res.message);
                }
            }, 'json')
        });


    })


</script>


</body>
</html>